﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    //链表节点
    public class Node<T> {
        public Node<T> Next { get; set; }
        public T data { get; set;}
        public Node(T d)
        {
            Next = null;
            data = d;
        }
    }
    //泛型链表类
    public class GenericList<T>
    {
        private Node<T> head;
        private Node<T> tail;
        public GenericList()
        {
            tail = head = null;
        }
        public Node<T> Head
        {
            get => head;
        }
        public void Add(T d)
        {
            Node<T> n = new Node<T>(d);
            if (tail == null)
            {
                head = tail = n;
            }
            else
            {
                tail.Next = n;
                tail = n;
            }
        }
    public void ForEach(Action<T> action)
    {
        Node<T> current = head;
        while (current != null)
        {
            action(current.data);
            current = current.Next;
        }
    }
    }
public class program {
    static void Main(string[] args)
    {
        GenericList<int> intlist = new GenericList<int>();
        intlist.Add(1);
        intlist.Add(2);
        intlist.Add(3);
        //求和
        int sum = 0;
        intlist.ForEach(element => sum += element);
        Console.WriteLine(sum);
        //打印所有值
        intlist.ForEach(element=>Console.WriteLine(element));
        //求最小值
        
        int min = 10000;
        intlist.ForEach(element => {
            if (element < min)
                min = element;
        });
        Console.WriteLine(min);
        int max = -10000;
        intlist.ForEach(element => {
            if (element >max)
                max = element;
        });
        Console.WriteLine(max);
    }
}
